<template>
  <div class="person">
    <h2>这是一辆{{car.brand}}车，价值{{car.price}}万元</h2>
    <button @click="changeBrand">修改品牌</button>
    <button @click="changePrice">修改价格</button>
    <button @click="changeCar">修改汽车</button>
    <hr>
    <h2>当前求和为：{{sum}}</h2>
    <button @click="changeSum">点我+1</button>
    <br>
  </div>
</template>

<script lang="ts" setup name="Person">
  import {ref,reactive} from 'vue'
  // 数据
  let car = reactive({ brand: '奔驰', price: 100 })
  let sum = ref(0)
  // 方法
  function changeBrand() {
    car.brand = 'Audi'
  }
  function changePrice() {
    car.price += 10
  }
  function changeCar() {
    // car = {brand:'Toyota', price:20}
    // car = reactive({brand:'Toyota', price:20})
    Object.assign(car, {brand:'Toyota', price:20})
  }
  function changeSum() {
    sum.value += 1
  }
</script> 

<style scoped>
  .person {
      background-color: skyblue;
      box-shadow: 0 0 10px;
      border-radius: 10px;
      padding: 20px;
  }

  button {
    margin: 0 5px;
  }
</style>